import { appServer } from '@deepfos/service/es/common/request';
import { listTableServer } from '@/utils/request';
import type { PageList } from './formList';

export enum EnumAuth {
  NoAccess = 'NoAccess',
  Write = 'write',
}
export interface DataListItemFieldType {
  auth: EnumAuth;
  value?: string;
  lineIdValue?: string;
  label?: string;
}
export interface DataListItemType {
  [name: string]: DataListItemFieldType;
}
export interface IFormListData {
  povList: PageList[];
  dataList: DataListItemType[];
  columnList: PageList[];
  baseConfig: any;
  povDimensions: any;
  smartList: [];
  ltdrList: [];
  pageList: PageList[];
  // 参数条件
  variableList: PageList[];
  [key: string]: any;
  errorCode?: string;
}

export interface SortProps {
  colAlias: string;
  orderType: string;
}

export interface GetListTableDataOptions {
  elementName: string;
  folderId?: string;
  page?: number;
  pageSize?: number;
  screen?: ScreenProp[];
  pov?: Record<string, unknown>;
  sort?: SortProps[];
  search?: string;
  path?: string;
  init?: boolean; // true 为首次开表
}

export interface ScreenProp {
  colAlias: string;
  filterType: string;
  value: string;
  valueType: number;
}

/**
 * 清单表列表请求接口
 */
export async function getListTableData(data: GetListTableDataOptions): Promise<IFormListData> {
  return listTableServer.post(`/list-table/data`, {
    data,
  });
}

interface PermissionRes {
  elementName: string;
  elementType: string;
  folderId: string;
  permission: 1 | 2 | 3 | 4 | null;
}
// 元素权限查询接口
export async function getElementPermission(
  data: {
    elementName: string;
    folderId?: string;
    path?: string;
    elementType: string;
  }[],
): Promise<PermissionRes[]> {
  return appServer.post(`/elements/get-element-permission-by-type`, {
    data,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  });
}
